<!DOCTYPE html>
<html>
<head lang="zh">
    <meta charset="UTF-8">
    <title>${tenantId???string("编辑", "添加")}租户信息</title>
<#include "admin/common.ftl"/>
<#include "admin/permission.ftl"/>
    <style type="text/css">
        #fm table tr td:first-child {text-align:right}
    </style>
</head>
<body>
<form id="fm" action="${base}/admin/tenant/save" method="post">
    <table cellpadding="5">
        <tr>
            <td>代码:</td>
            <td><input class="easyui-textbox ehome-input" id="id" name="id" value="<#if tenant??>${tenant.id}</#if>"
                       data-options="required:true,
                       validType:{
                           maxLength:[10],
                           integer:true,
                           numericRange:[1,99999],
                           remote:['${base}/admin/tenant/existsCode?tenantId=${tenantId!}', 'code']
                       }"/></td>
        </tr>
        <tr>
            <td>名称:</td>
            <td><input class="easyui-textbox ehome-input" id="name" name="name" value="<#if tenant??>${tenant.name}</#if>"
                       data-options="required:true,
                       validType:{
                           maxLength:[200],
                           remote:['${base}/admin/tenant/existsName?tenantId=${tenantId!}', 'name']
                       }"/></td>
        </tr>
        <tr>
            <td>简称:</td>
            <td><input class="easyui-textbox ehome-input" id="shortName" name="shortName" value="<#if tenant??>${tenant.shortName}</#if>"
                       data-options="required:true,
                       validType:{
                           maxLength:[30],
                           remote:['${base}/admin/tenant/existsShortName?tenantId=${tenantId!}', 'shortName']
                       }"/></td>
        </tr>
        <tr>
            <td>描述:</td>
            <td><input class="easyui-textbox ehome-textarea" id="description" name="description" data-options="multiline:true,value:'<#if tenant??>${tenant.description!}</#if>',validType:'maxLength[255]'"/></td>
        </tr>
    </table>

    <div style="width: 450px;text-align: center">
        <a id="btnSave" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ehome-standard-save',onClick:save">保 存</a>&nbsp;
        <a id="btnCancel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ehome-standard-cancel',onClick:closeLayer">取 消</a>
    </div>
</form>

<script src="${base}/static/jquery-plugins/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function() {
        rewriteDomElementStyle();
        initEscEvent();
    });

    <#if hasSave == "true">
    // 保存
    function save() {
        var fm = $("#fm");
        if (fm.form("validate")) {
            fm.ajaxSubmit({
                success: function (data) {
                    var result = JSON.parse(data);
                    var status = result.status;
                    if (status == "success") {
                        parent.reloadGrid();
                        closeLayer();
                    } else {
                        layer.alert(result.msg, {title: "错误提示", icon: 2});
                    }
                }
            });
        }
    }
    </#if>

    // 关闭当前layer页面
    function closeLayer() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    // 初始化ESC事件
    function initEscEvent() {
        // 使一个可见元素先focus
        $("#name").parent().find("span input:not('hidden')").focus();
        document.onkeyup = function (e) {
            e = e || window.event;
            var code = e.which || e.keyCode;
            if (code == 27) {
                closeLayer();
            }
        }
    }
</script>
</body>
</html>